package day13;

import java.util.Scanner;

public class demo1 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        while (n>0){
            int x= in.nextInt();
            int k= in.nextInt();
            String str=in.next();
            int count=0;
            int ret=0;
            for (int i = 0; i <x ; i++) {
                if(str.charAt(i)=='L'){
                    ret--;
                    count=0;
                }
                else if(count>=2){
                    ret+=k;
                    count++;
                }else {
                    ret++;
                    count++;
                }
            }
            System.out.println(ret);
            n--;
        }
    }
}
